"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/11/13 10:21
@Description :   数据库连接池
1. 安装连接池
   pip install dbutils
"""
import pymysql
from dbutils.pooled_db import PooledDB

# 创建连接池对象
db_pool = PooledDB(
    host='127.0.0.1',
    port=3306,
    user='root',
    passwd='root',
    db='python2514',
    charset='utf8mb4',
    creator=pymysql,  # 连接数据库的模块
)

#  获取连接
conn = db_pool.connection()
cur = conn.cursor()
cur.execute('select * from user')
for row in cur.fetchall():
    print(row)
cur.close()
conn.close()
